package top.rainbowecho.gateway.security.authentication.social;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.view.AbstractView;
import top.rainbowecho.common.domain.shared.vo.ResponseResult;
import top.rainbowecho.common.util.CommonUtil;
import top.rainbowecho.common.util.ResultKey;
import top.rainbowecho.common.util.ResultParamFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author rainbow
 * @since 2019/12/16 12:42
 */
public class SocialConnectView extends AbstractView {
    private ObjectMapper objectMapper;

    public void setObjectMapper(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    @Override
    protected void renderMergedOutputModel(Map<String, Object> map, HttpServletRequest request, HttpServletResponse response) throws Exception {
        String mess = map.get("connection") == null ? "解绑成功" : "绑定成功";
        Map<String, Object> param = new ResultParamFactory().add(ResultKey.MESS, mess).build();
        ResponseResult result = new ResponseResult(true, HttpStatus.OK, param);

        String json = objectMapper.writeValueAsString(result);
        CommonUtil.jsonResponse(response, json);
    }
}
